﻿using SlamCmsDemo.Data;

namespace SlamCmsDemo.Web.Core
{
	public static class EventExtensions
	{
		public static string ToFormattedEventDate(this Event @event)
		{
			string eventDate = "";

			if (@event.StartDate.ToString("D") == @event.EndDate.ToString("D"))
				eventDate = @event.StartDate.ToString("D") + "<br />" + @event.StartDate.ToString("t") + (@event.StartDate.ToString("t") != @event.EndDate.ToString("t") ? " - " + @event.EndDate.ToString("t") : "");
			if (@event.StartDate == @event.EndDate)
				eventDate = @event.StartDate.ToString("D") + "<br />" + @event.StartDate.ToString("t");
			if (@event.AllDayEvent)
				eventDate = @event.StartDate.ToString("D");
			if (@event.StartDate.ToString("MMMM yyyy") == @event.EndDate.ToString("MMMM yyyy") && @event.StartDate.ToString("dd") != @event.EndDate.ToString("dd"))
				eventDate = @event.StartDate.ToString("MMMM dd") + " - " + @event.EndDate.ToString("dd") + ", " + @event.StartDate.ToString("yyyy");
			if (@event.StartDate.ToString("MMMM yyyy") != @event.EndDate.ToString("MMMM yyyy"))
				eventDate = @event.StartDate.ToString("MMMM dd") + " - " + @event.EndDate.ToString("MMMM dd") + ", " + @event.StartDate.ToString("yyyy");
			if (@event.StartDate.ToString("MMMM yyyy") != @event.EndDate.ToString("MMMM yyyy") && @event.StartDate.ToString("yyyy") != @event.EndDate.ToString("yyyy"))
				eventDate = @event.StartDate.ToString("MMMM dd yyyy") + " - " + @event.EndDate.ToString("MMMM dd yyyy");

			return eventDate;
		}
	}
}